package com.gps.pe.model;

import java.io.Serializable;

/**
 * 
 * @author Gps
 *
 */
public class Role implements Serializable {

	private static final long serialVersionUID = 1L;

	private int roleId;
	private String roleName;
	private String readAccess;
	private String writeAccess;

	public int getRoleId() {
		return roleId;
	}

	public void setRoleId(int roleId) {
		this.roleId = roleId;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getReadAccess() {
		return readAccess;
	}

	public void setReadAccess(String readAccess) {
		this.readAccess = readAccess;
	}

	public String getWriteAccess() {
		return writeAccess;
	}

	public void setWriteAccess(String writeAccess) {
		this.writeAccess = writeAccess;
	}

	/**
	 * The roleName is unique for each Role. So this should compare Role by name
	 * only.
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object other) {
		return (other instanceof Role) ? roleName.equals(((Role) other).roleName) : (other == this);
	}

	/**
	 * The roleName is unique for each Role. So Role with same name should
	 * return same hashcode.
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return (roleName != null) ? (this.getClass().hashCode() + roleId + roleName.hashCode()) : super.hashCode();
	}

	/**
	 * Returns the String representation of this Role. Not required, it just
	 * pleases reading logs.
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return String.format("Role[roleId=%d,roleName=%s,readAccess=%s,writeAccess=%s]", roleId, roleName, readAccess,
				writeAccess);
	}
}
